<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3]
    // 数组的去重
    let newArr = [...new Set(arr)]
    console.log(newArr);    // (9) [1, 2, 3, 4, 5, 6, 7, 8, 9]

    let arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    let arr2 = [2, 3, 4, 5, 6, 7, 8, 9, 10]

    // 交集
    let newArr1 = arr1.filter(item => arr2.includes(item))
    console.log(newArr1);   // (8) [2, 3, 4, 5, 6, 7, 8, 9]

    // 并集
    let newArr2 = [...new Set([...arr1, ...arr2])]
    console.log(newArr2);   // (10) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

    // 差集
    let newArr3 = arr1.filter(item => !arr2.includes(item))
    console.log(newArr3);   // [1]
    let newArr4 = arr2.filter(item => !arr1.includes(item))
    console.log(newArr4);   // [10]

  </script>
</body>

</html>